import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent, STPage } from '@delon/abc/table';
import { SFSchema, SFComponent, SFRadioWidgetSchema } from '@delon/form';
import { LbWjfwComponent } from '@shared/components/lb_wjfw/lbwjfw.component';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';
import { ReuseTabService } from '@delon/abc';
import { HttpService, SupDic } from 'lbf';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ActivatedRoute } from '@angular/router';
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
import { LbRepComponent } from '@shared/components/lb-rep/lb-rep.component';

@Component({
  selector: 'app-zyjk-zcsh',
  templateUrl: './zcsh.component.html',
})
export class ZyjkZcshComponent implements OnInit {
  tabs = ['办件信息', '材料影像'];
  dataset = [];
  PROJID = '1';
  DAD069 = '';
  params = { sname: 'BJXX_QUERY', queryparas: {} };
  datass = [];
  isVisible1 = false;
  isOkLoading1 = false;
  slSchema: SFSchema = {
    properties: {
      DAD095: {
        type: 'string',
        title: '',
        enum: [
          { label: '受理', value: '1' },
          { label: '不受理', value: '0' },
        ],
        // tslint:disable-next-line: no-object-literal-type-assertion
        ui: {
          widget: 'radio',
          // asyncData: () => of().pipe(delay(100)),
          change: console.log,
          grid: {
            span: 24,
          },
        } as SFRadioWidgetSchema,
        default: '1',
      },
      DAD098: {
        type: 'string',
        title: '不予受理原因',
        ui: {
          visibleIf: { DAD095: ['0'] },
          spanLabelFixed: 150,
          grid: { span: 24 },
        },
      },
    },
    ui: { grid: { span: 24 } },
    required: ['DAD098'],
  };

  constructor(
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
    private modalService: NzModalService,
  ) {
    this.reuseTabService.title = '基本医疗保险审核';
  }

  sffschema: SFSchema = {
    properties: {
      AAC002: {
        title: '证件号',
        type: 'string',
        ui: { hidden: true },
      },
      AAC003: {
        title: '姓名',
        type: 'string',
        ui: { hidden: true },
      },
    },
    ui: {
      grid: { span: 12 },
      spanLabelFixed: 150,
    },
  };

  // 本地获取数据
  ppdl: SFSchema = {
    properties: {
      AAC001: {
        title: '个人编码',
        type: 'string',
        readOnly: true,
      },
      AAE140: {
        title: '险种类型',
        type: 'string',
        readOnly: true,
        enum: [{ label: '职工基本医疗310', value: '310' }],
        default: '310',
      },
      DAC133: {
        type: 'string',
        title: '转移档案号',
        readOnly: true,
      },

      AAC002: {
        title: '社会保障号',
        type: 'string',
        readOnly: true,
      },

      AAC003: {
        title: '姓名',
        type: 'string',
        readOnly: true,
      },

      AAC004: {
        title: '性别',
        type: 'string',
        readOnly: true,
        enum: [
          { label: '男', value1: '1' },
          { label: '女', value: '2' },
        ],
      },

      AAC010: {
        title: '户籍地地址',
        type: 'string',
        readOnly: true,
      },

      AAB004: {
        title: '转出单位名称',
        type: 'string',
        readOnly: true,
      },

      AAC049: {
        title: '参加工作时间',
        type: 'string',
        readOnly: true,
        // ui:{
        //    displayFormat:'yyyyMM'
        // }
      },

      AAB305: {
        title: '首保地个人缴费时间',
        type: 'string',
        readOnly: true,
      },

      AAE030: {
        title: '本地缴费起始时间',
        type: 'string',
        readOnly: true,
      },

      AAE031: {
        title: '本地缴费终止时间',
        type: 'string',
        readOnly: true,
      },

      LNZHYE: {
        title: '历年结转额',
        type: 'string',
        readOnly: true,
      },

      BNZHYE: {
        title: '本年账户额',
        type: 'string',
        readOnly: true,
      },
      AAE035: {
        title: '转移日期',
        type: 'string',
        readOnly: true,
      },
      AAE473: {
        title: '转移账户类别',
        type: 'string',
        readOnly: true,
        enum: this.supDic.getSFDic('AAE473'),
        ui: {
          widget: 'select',
        },
      },
      AAC105: {
        title: '转移地域范围',
        type: 'string',
        readOnly: true,
        enum: this.supDic.getSFDic('BAE011'),
        ui: {
          widget: 'select',
        },
      },
      SBJG: {
        title: '对方社保名称',
        type: 'string',
        readOnly: true,
        ui: {
          onlyVisual: true,
        },
      },

      RECACCNO: {
        title: '银行帐号',
        readOnly: true,
        type: 'string',
      },
      RECACCNAMECN: {
        title: '账户名称',
        type: 'string',
        readOnly: true,
      },
      RECBANKNAME: {
        title: '银行名称',
        type: 'string',
        readOnly: true,
      },
      SBJGDZ: {
        title: '地址',
        type: 'string',
        readOnly: true,
      },
      SBJGYB: {
        title: '邮编',
        type: 'string',
        readOnly: true,
      },

      LXHBH: {
        title: '联系函编号',
        type: 'string',
        readOnly: true,
      },
      AAE013: {
        type: 'string',
        title: '备注',
        readOnly: true,
        ui: {
          grid: { span: 24 },
        },
      },
    },
    ui: {
      grid: { span: 8 },
      spanLabelFixed: 150,
    },
  };

  bbColumns: STColumn[] = [
    { title: '序号', index: 'SID', type: 'no' },
    { title: '缴费起始年月', index: 'AAE041' },
    { title: '缴费终止年月', index: 'AAE042' },
    { title: '基本医疗保险类型', index: 'YBLX' },
    { title: '参保缴费月数小计', index: 'AAE202' },
    { title: '统筹地区经办机构名称', index: 'AAC072' },
    { title: '统筹地区行政区划代码', index: 'AAB301' },
    { title: '备注', index: 'AAE013' },
  ];

  tabMode = 'bjxx';
  @ViewChild('bbst', { static: false }) bbst: STComponent;
  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('slxx', { static: false }) slxx: SFComponent;
  @ViewChild('wjfw', { static: false }) wjfw: LbWjfwComponent;
  @ViewChild('step', { static: true }) step: LbStepsComponent;
  @ViewChild('sffd', { static: false }) sffd: SFComponent;
  @ViewChild('sf1', { static: false }) sf1: SFComponent;

  clsmcolumns: STColumn[] = [
    { title: '序号', index: 'RN', width: '10%' },
    { title: '材料名称', index: 'STUFFNAME', width: '50%' },
    { title: '材料数量', index: 'STUFFNUM', width: '25%' },
    { title: '收件类型', index: 'STUFFTYPE', width: '15%' },
  ];

  page: STPage = {
    show: false,
  };

  ngOnInit() {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 打开情况下再次传入值
  _onReuseInit(): void {
    if (this.activateroute.snapshot.queryParams.PROJID) {
      this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
      this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
      this.YB_QUERY();
      this.YBCL_QUERY();
    }
  }

  // 事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }

  // 界面赋值
  YB_QUERY() {
    this.lbservice
      .lbservice('YB_QUERY', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf.formData = JSON.parse(resdata.message);
          this.sf.reset();
          // 页面加载的时候调用后台获取值
          this.Yb_fanh();
        }
      });
  }

  // 材料列表
  YBCL_QUERY() {
    this.lbservice
      .lbservice('YBCL_QUERY', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code === 0) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.dataset = resdata.message.list;
        }
      });
  }

  // 审核
  // lc_yb_sh(value1: any) {
  //   // tslint:disable-next-line: all
  //   if (value1.DAD095 == '0') {
  //     if (!this.slxx.valid) {
  //       return this.msgSrv.error('没有填写必填项');
  //     }
  //     this.lbservice
  //       .lbservice('P_Yb_sh_save', {
  //         para: {
  //           PROJID: this.PROJID,
  //           sf: this.sf.value,
  //           slxx: this.slxx.value,
  //           DAD069: this.DAD069,
  //           bbst: this.bbst.data,
  //           sf1: this.sf1.value,
  //         },
  //       })
  //       .then(resdata => {
  //         if (resdata.code < 1) {
  //           this.msgSrv.error(resdata.errmsg);
  //         } else {
  //           this.msgSrv.info('成功');
  //           this.sf.formData = null;
  //           this.sf.reset();
  //           this.isVisible1 = true;
  //         }
  //       });
  //   } else {
  //     this.lbservice
  //       .lbservice('P_Yb_sh_save', {
  //         para: {
  //           PROJID: this.PROJID,
  //           sf: this.sf.value,
  //           slxx: this.slxx.value,
  //           DAD069: this.DAD069,
  //           bbst: this.bbst.data,
  //           sf1: this.sf1.value,
  //         },
  //       })
  //       .then(resdata => {
  //         console.log(resdata);
  //         if (resdata.code < 1) {
  //           this.msgSrv.error(resdata.errmsg);
  //         } else {
  //           this.msgSrv.info('成功');
  //           this.sf.formData = null;
  //           this.sf.reset();
  //         }
  //       });
  //   }
  // }

  //转出审核
  lc_yb_sh(value1: any) {
    this.lbservice
      .lbservice('P_Yb_sh_save', {
        para: {
          PROJID: this.PROJID,
          sf: this.sf.value,
          slxx: this.slxx.value,
          DAD069: this.DAD069,
          bbst: this.bbst.data,
          sf1: this.sf1.value,
        },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.msgSrv.info('审核成功');
          this.isVisible1 = true;
          this.sf.formData = null;
          this.sf.reset();
        }
      });
  }

  // 根据身份证返回前端数据
  Yb_fanh() {
    this.lbservice
      .lbservice('P_Yb_sh_sc', {
        para: { PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf1.formData = resdata.message.list[0];
          console.log('ssss*******');
          console.log(resdata);
          this.sf1.reset();
        }
      });

    this.h_Yb_fanh();
  }
  h_Yb_fanh() {
    this.lbservice
      .lbservice('P_Yb_sh_sc_j', {
        para: { sf: this.sf.value, PROJID: this.PROJID },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.datass = resdata.message.list;

          // this.bbst.reset();
        }
      });
  }
  // 打印

  //是否打印页面
  handleOk1(): void {
    this.isOkLoading1 = true;
    this.print();
    setTimeout(() => {
      this.isVisible1 = false;
      this.isOkLoading1 = false;
    }, 3000);
  }
  handleCancel1(): void {
    this.isVisible1 = false;
  }
  // 打印
  print() {
    const modal = this.modalService.create({
      nzTitle: '打印',
      nzContent: LbRepComponent,
      nzComponentParams: {
        repid: '52',
        inpara: { DAD069: this.DAD069 },
      },
      nzWidth: 1000,
    });
  }

  // disabled: true,
  // tslint:disable-next-line: member-ordering
  pl = {
    pname1: '本地数据',
    active1: true,
    pname2: '数据详情',
    active2: false,
  };
  // tslint:disable-next-line:all
  icon1 = 'caret-right';
  // tslint:disable-next-line: member-ordering
}
